package com.blog4j.article.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.blog4j.article.service.LabelService;
import com.blog4j.article.vo.req.CreateLabelReqVo;
import com.blog4j.article.vo.req.DeleteLabelReqVo;
import com.blog4j.article.vo.req.EditLabelReqVo;
import com.blog4j.common.annotation.OperationLog;
import com.blog4j.common.enums.ModuleTypeEnum;
import com.blog4j.common.enums.OperationTypeEnum;
import com.blog4j.common.model.Result;
import com.blog4j.requestRate.annotation.RequestRate;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author 98k灬
 * @version v1.0.0
 * @Description : 功能描述
 * @Create on : 2024/7/23 12:40
 **/
@RestController
@RequestMapping("/label")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class LabelController {
    private final LabelService labelService;

    /**
     * 编辑标签信息
     *
     * @param reqVo 请求信息
     * @return 编辑成功
     */
    @RequestRate(count = 5)
    @OperationLog(operationType= OperationTypeEnum.EDIT,
            module= ModuleTypeEnum.ARTICLE,
            description = "编辑标签信息")
    @SaCheckPermission("LABEL:EDIT")
    @PostMapping("/edit")
    public Result edit(@RequestBody @Valid EditLabelReqVo reqVo) {
        labelService.edit(reqVo);
        return Result.ok();
    }

    /**
     * 创建标签信息
     *
     * @param reqVo 请求信息
     * @return 创建成功
     */
    @RequestRate(count = 5)
    @OperationLog(operationType= OperationTypeEnum.INSERT,
            module= ModuleTypeEnum.ARTICLE,
            description = "创建标签信息")
    @SaCheckPermission("LABEL:ADD")
    @PostMapping("/create")
    public Result create(@RequestBody @Valid CreateLabelReqVo reqVo) {
        labelService.create(reqVo);
        return Result.ok();
    }

    /**
     * 删除标签信息
     *
     * @param reqVo 请求信息
     * @return 删除成功
     */
    @RequestRate(count = 5)
    @OperationLog(operationType= OperationTypeEnum.DELETE,
            module= ModuleTypeEnum.ARTICLE,
            description = "删除标签信息")
    @SaCheckPermission("LABEL:DELETE")
    @PostMapping("/delete")
    public Result delete(@RequestBody @Valid DeleteLabelReqVo reqVo) {
        labelService.delete(reqVo);
        return Result.ok();
    }
}
